package com.common.weibolib;

import org.json.JSONException;
import org.json.JSONObject;

public class ImageParser extends AbstractObjParser<Image>{

	@Override
	public Image parse(JSONObject json) throws JSONException {
		Image image = new Image();
		if(null == json){
			return image;
		}
		image.id = json.optString("id");
		image.image_original = json.optString("image_original");
		image.image_middle = json.optString("image_middle");
		image.image_thumb = json.optString("image_thumb");
		image.image_height = json.optInt("image_height");
		image.image_width = json.optInt("image_width");
		image.image_size = json.optLong("image_size");
		image.image_ext = json.optString("image_ext");
		return image;
	}

	@Override
	public JSONObject toJSONObject(Image t) throws JSONException {
		JSONObject json = new JSONObject();
		if(null == t){
			return json;
		}
		json.put("id", t.id);
		json.put("image_original", t.image_original);
		json.put("image_middle", t.image_middle);
		json.put("image_thumb", t.image_thumb);
		json.put("image_height", t.image_height);
		json.put("image_width", t.image_width);
		json.put("image_size", t.image_size);
		json.put("image_ext", t.image_ext);
		return json;
	}
}
